<template>
  <div>
    <!-- 新增,编辑的弹出框 -->
    <el-dialog title="新增信息" :visible.sync="dialogFormVisible">
      <el-form :model="formData">
        <el-form-item label="用户名：" label-width="180px">
          <el-input v-model="formData.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注：" label-width="180px">
          <el-input v-model="formData.remarks" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="是否启用：" label-width="180px" v-if="showEagleMap" disabled="disabled">
          <el-input v-model="formData.isactived" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel ">取 消</el-button>
        <el-button type="primary" 
        >确 定</el-button>
      </div>
    </el-dialog>

    <el-card class="box-card">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="审批人">
          <el-input placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="success" >新增</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column type="index" label="序号" width="60" :index="indexMethod" align="center" />

      <el-table-column label="Id">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户端地址">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.clientIpAddress}}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行时间">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.executionDuration }}</span>
        </template>
      </el-table-column>
     <el-table-column label="执行时间">
        <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>参数: {{ scope.row.parameters }}</p>
          <p>返回数据: {{ scope.row.returnValue }}</p>
          <p>服务名称: {{ scope.row.serviceName }}</p>
          <p>方法名称: {{ scope.row.methodName }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.executionDuration }}</el-tag>
          </div>
        </el-popover>
      </template>
      </el-table-column>
      <el-table-column label="备注">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.remarks }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="180px">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pager.pageIndex"
        :page-size="pager.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pager.rowsTotal"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getList, } from "../api/log";
export default {
  data() {
    return {
      //v-if隐藏输入框
      showEagleMap: true,
      //绑定的数据
      tableData: [],
      //分页
      pager: {
        pageIndex: 1, //页码
        pageSize: 10, //页面大小
        rowsTotal: 30 //总条数
      },
      //增加，编辑返回的数据
      formData: {
        id: 0,
        username: "",
        remarks: "",
        password: "113"
        // isactived:''
      },
      //增加，编辑的弹出框
      dialogFormVisible: false
    };
  },
  methods: {
    //序号列随便页面的变化而变化
    indexMethod(index) {
      index = index + 1 + (this.pager.pageIndex - 1) * this.pager.pageSize;
      return index;
    },
    //弹出框取消按钮
    handleCancel() {
      this.dialogFormVisible = false;
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    //页面条数修改后重新拉取数据
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pager.pageSize = val;
      this.fetchData(this.pager);
    },
    //页面页数修改后重新拉取数据
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pager.pageIndex = val;

      this.fetchData(this.pager);
    },
    //拉取数据方法
    fetchData(pager) {
      getList(pager)
        .then(( data ) => {
          console.log(data.data.data);
          let res = data.data;
          this.tableData = res.data;
          // console.log(res.pager);
          this.pager = res.pager;
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  mounted() {
    // getById(1).then(({data})=>{
    //   console.log(data);
    // }).catch(err=>{
    //   console.log(err);
    // });

    this.fetchData(this.pager);
  }
};
</script>
<style>
</style>